package history;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.ListIterator;
import common.Data;

/**
 * Basic interface measurements history.
 * 
 * Set to provide basic functionalities for file storing (by date ordered), recording and accessing measurements - later to be used as data source for graph plotting.  
 * 
 * @author Kamil "Mamut" Balwierz <kamil.balwierz@gmail.com>
 */
public interface DataHistory {
	
	/**
	 * Records single measurement.
	 * 
	 * @param data measurement to be recorded
	 */
	public void add(Data data);
	
	/**
	 * Provides iterator to sorted by date list of measurements starting with corresponding to date supplied in parameter
	 *  
	 * @param data Start date for iterator
	 * @return measurements list iterator 
	 */
	public ListIterator<Data> iteratorByDate(Date data);
	
	/**
	 * Provides iterator to sorted by date list of measurements starting at earliest measurement. 
	 * 
	 * @return measurements list iterator
	 */
	public ListIterator<Data> iteratorFront();
	
	/**
	 * Provides iterator to sorted by date list of measurements starting after last measurement. 
	 * 
	 * @return measurements list iterator
	 */
	public ListIterator<Data> iteratorEnd();
	
	/**
	 * Provides single measurement corresponding to supplied date in parameter 
	 * 
	 * @param data Date corresponding with measurement
	 * @return measurement
	 */
	public Data elementByDate(Date data);
	
	/**
	 * Provides first recorded measurement
	 * 
	 * @return first recorded measurement
	 */
	public Data elementFirst();
	
	/**
	 * Provides last recorded measurement
	 * 
	 * @return last recorded measurement
	 */
	public Data elementLast();
	
	/**
	 * Loads archive measurements from file
	 * 
	 * Appends measurements loaded from file to existing set of measurements
	 * 
	 * @param file file with measurements to load
	 * @return number of loaded measurements
	 * @throws IOException nasty things might happen while reading a file ... seriously ...
	 */
	public int load(File file) throws IOException;
	
	/**
	 * Saves measurements to file archive
	 * 
	 * @param file archive for writing
	 * @throws IOException I'm serious things happen when writing files ...
	 */
	public void save(File file) throws IOException;
	
	/**
	 * Returns count of registered measurements.
	 * 
	 * @return measurements count
	 */
	public int getCount();
	
	public void registerListener(DataHistoryListener listener);
}
